package com.wteam.dragon.name.controller;

import com.wteam.dragon.model.pojo.bean.SystemConfig;
import com.wteam.dragon.model.pojo.vo.SystemConfigVo;
import com.wteam.dragon.name.service.CommonUserService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.apps.security.annotation.AnonymousAccess;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 陈晓辉
 * @Date 2021/6/11 9:47
 */
@RestController
@Api(tags = "用户管理")
@RequestMapping("commonUser")
@RequiredArgsConstructor
public class CommonUserController {
    private final CommonUserService commonUserService;

    @Log("初始化")
    @ApiOperation("初始化")
    @GetMapping("init")
    @AnonymousAccess
    public ResultMessage init() {
        return commonUserService.init();
    }

    @ApiOperation("编辑配置")
    @PutMapping("editSys")
    @PreAuthorize("@el.check('editSys')")
    public ResultMessage editSys(SystemConfigVo systemConfigVo) {
        SystemConfig systemConfig = BeanUtil.from(systemConfigVo, SystemConfig.class);
        return commonUserService.editSys(systemConfig);
    }
}
